namespace OracleInternal.Network
{
	internal class SupervisorService : AnoService
	{
		internal const int NAS_OK = 31;

		internal const int NAS_CLIENT_SERVICES_UNAVAILABLE = 47;

		internal const int NAS_SERVER_SERVICES_UNAVAILABLE = 63;

		internal const int NAS_NO_SERVICES_AVAILABLE = 79;

		internal const int NAS_SERVICE_REQUIRED = 95;

		internal const int NAS_REQUIRED_SERVICE_UNAVAILABL = 111;

		internal const int NAS_SERVICE_UNAVAILABLE = 127;

		private byte[] m_cid = new byte[8]
		{
			0,
			0,
			16,
			28,
			102,
			236,
			40,
			234
		};

		private int[] m_servicesArray;

		private int[] m_serverServices;

		private int m_servicesValidated;

		private int m_servicesWanted;

		internal SupervisorService()
		{
		}

		internal override int Initialize(SessionContext sessCtx)
		{
			base.Initialize(sessCtx);
			m_service = 4;
			m_servicesValidated = 0;
			m_servicesWanted = 2;
			m_servicesArray = new int[4];
			m_servicesArray[0] = 4;
			m_servicesArray[1] = 1;
			m_servicesArray[2] = 2;
			m_servicesArray[3] = 3;
			return 1;
		}

		internal byte[] CreateCID()
		{
			return m_cid;
		}

		internal override void SendServiceData()
		{
			SendHeader(3);
			m_anoComm.SendVersion();
			m_anoComm.SendRaw(m_cid);
			m_anoComm.SendUB2Array(m_servicesArray);
		}

		internal override int GetServiceDataLength()
		{
			return 12 + m_cid.Length + 4 + 10 + m_servicesArray.Length * 2;
		}

		internal override void ReceiveServiceData(int numSubPackets)
		{
			m_version = m_anoComm.ReceiveVersion();
			if (m_anoComm.ReceiveStatus() != 31)
			{
				throw new NetworkException(-6306);
			}
			m_serverServices = m_anoComm.receiveUB2Array();
		}

		internal override void ValidateResponse()
		{
			int num = 0;
			int num2 = 0;
			for (num = 0; num < m_serverServices.Length; num++)
			{
				for (num2 = 0; num2 < m_servicesArray.Length; num2++)
				{
					if (m_serverServices[num] == m_servicesArray[num2])
					{
						m_servicesValidated++;
						break;
					}
				}
				if (num2 == m_servicesArray.Length)
				{
					throw new NetworkException(-6320);
				}
			}
			if (m_servicesValidated != m_servicesWanted)
			{
				throw new NetworkException(-6321);
			}
		}
	}
}
